home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AEWIN100.ARJ / WINLIST.CC < prev   
C/C++ Source or Header  |  1991-10-27  |  2KB  |  114 lines

  1. /**********************************************************************
  2.  *  
  3.  *  NAME:           winlist.cpp
  4.  *  
  5.  *  DESCRIPTION:    manage a front to back list of windows
  6.  *  
  7.  *  copyright (c) 1990 J. Alan Eldridge
  8.  * 
  9.  *  M O D I F I C A T I O N   H I S T O R Y
  10.  *
  11.  *  when        who                 what
  12.  *  -------------------------------------------------------------------
  13.  *  12/25/90    J. Alan Eldridge    created
  14.  *  
  15.  *********************************************************************/
  16.  
  17. #include    "w.h"
  18.  
  19. #define MAXWINS 32
  20.  
  21. static int      nwins = 0;
  22. static Window   *wins[ MAXWINS ];
  23.  
  24. //  delete the window at position n
  25.  
  26. static void
  27. delwin(int n)
  28. {
  29.     for (; n < nwins - 1; n++)
  30.         wins[n] = wins[n+1];
  31.     nwins--;
  32. }
  33.         
  34. //  insert a new window at the front of the list
  35.  
  36. void
  37. Window::newtop()
  38. {
  39.     if (nwins > 0)
  40.         wins[0]->deactivate();
  41.     for (int n = nwins; n > 0; n--)
  42.         wins[n] = wins[n-1];
  43.     (wins[0] = this)->activate();
  44.     nwins++;
  45. }    
  46.  
  47. //  is a window in the list?
  48.  
  49. static int
  50. find(Window *w)
  51. {
  52.     for (int n = nwins - 1; n >= 0; n--)
  53.         if (wins[n] == w) break;
  54.     return n;
  55. }
  56.  
  57. //  is this the top window?
  58.  
  59. int
  60. Window::istop()
  61. {
  62.     return nwins > 0 && wins[0] == this;
  63. }
  64.  
  65. //  make this the top window
  66.  
  67. int
  68. Window::maketop(int show)
  69. {
  70.     int n = find(this);
  71.     
  72.     if (n) {
  73.         if (n > 0)
  74.             delwin(n);
  75.     
  76.         if (nwins < MAXWINS)
  77.             newtop();
  78.         else
  79.             return ERR;
  80.     }
  81.  
  82.     if (show)
  83.         refresh();
  84.  
  85.     return OK;
  86. }
  87.  
  88. //  remove this from the list and activate
  89. //  new top (if there is one)
  90.  
  91. void
  92. Window::unlink()
  93. {
  94.     int n = find(this);
  95.     
  96.     if (n >= 0) {
  97.         delwin(n);
  98.         if (!n && nwins > 0)
  99.             wins[0]->activate();
  100.     }
  101. }
  102.  
  103. //  find which window the mouse went down in
  104.  
  105. Window *
  106. findwin(int &y, int &x)
  107. {
  108.     for (int n = 0; n < nwins; n++)
  109.         if (wins[n]->inwindow(y, x))
  110.             return wins[n];
  111.  
  112.     return 0;
  113. }
  114.